package br.jm.mala.entity;

import java.io.Serializable;
import java.util.List;
import javax.persistence.Basic;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Transient;
import javax.validation.constraints.NotNull;
import org.hibernate.annotations.LazyCollection;
import org.hibernate.annotations.LazyCollectionOption;

import org.springframework.security.core.GrantedAuthority;

/**
 *
 * @author joao
 */
@Entity
@Table(name = "roles", catalog = "mala", schema = "dbo")
public class Roles implements Serializable, GrantedAuthority {
    private static final long serialVersionUID = -3968396919486158590L;

    private Integer role_id;
    private String description;
    private String nomFantasia;
    @LazyCollection(LazyCollectionOption.FALSE)
    private List<Modulos> rolesModulosList;

    public Roles() {
    }

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Basic(optional = false)
    @Column(name = "role_id")
    @NotNull
    public Integer getRole_id() {
        return role_id;
    }

    public void setRole_id(Integer role_id) {
        this.role_id = role_id;
    }

    @Column(name = "description", unique = true)
    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    @Override
    @Transient
    public String getAuthority() {
        return description;
    }

    @Column(name = "nom_fantasia", length = 30)
    public String getNomFantasia() {
        return nomFantasia;
    }

    public void setNomFantasia(String nomFantasia) {
        this.nomFantasia = nomFantasia;
    }

    @ManyToMany(fetch = FetchType.EAGER)
    @JoinTable(name = "roles_modulos", joinColumns = {
        @JoinColumn(name = "role_id")}, inverseJoinColumns = {
        @JoinColumn(name = "modulo_id")})
    public List<Modulos> getRolesModulosList() {
        return rolesModulosList;
    }

    public void setRolesModulosList(List<Modulos> rolesModulosList) {
        this.rolesModulosList = rolesModulosList;
    }
}
